package com.mycompany.javasockettcp01;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer {
    public static void main(String[] args) {
        try (
                ServerSocket serverSocket = new ServerSocket(8888);
                Socket socket = serverSocket.accept();) {
            System.out.println("服务启动成功");
//            InetAddress inetAddress = socket.getInetAddress();

            InputStream is = socket.getInputStream();
            byte[] text = new byte[1024];
            int len = is.read(text);
            String textInfo = new String(text, 0, len);
            System.out.println("[info]服务器" + textInfo);

            socket.getOutputStream().write("收到".getBytes());

        } catch (IOException e) {
            System.out.println("服务器异常");
        }
    }
}
